﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NH_Entity;
using NH_Map;

namespace NH_Factory
{
    public class NHibernateHelper
    {
        public static ISessionFactory CreateSessionFactory()
        {
            //   return Fluently.Configure()
            //.Database(MsSqlConfiguration
            //.MsSql2008
            //.ConnectionString(c => c.FromConnectionStringWithKey("DataContext")))
            //.Mappings(m => m.FluentMappings
            //.AddFromAssemblyOf<QHY_UserMap>()).ExposeConfiguration(CreateSchema)
            //.BuildSessionFactory();

            return Fluently.Configure()
           .Database(MySQLConfiguration
           .Standard
           .ConnectionString(c => c.FromConnectionStringWithKey("DataContext")))
           .Mappings(m => m.FluentMappings
           .AddFromAssemblyOf<QHY_UserMap>()).ExposeConfiguration(CreateSchema)
           .BuildSessionFactory();

        }


        private static void CreateSchema(Configuration cfg)
        {
            var schemaExport = new SchemaExport(cfg);
            //schemaExport.SetOutputFile("e:\\abc.sql");
            schemaExport.Create(false, false);
        }

        public static ISessionFactory sessionFactory = NHibernateHelper.CreateSessionFactory();
    }
}